package reflectdemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—07—23
 * Time: 14:54
 */

class Student{
    //私有属性name
    private String name = "guanyu";
    //公有属性age
    public int age = 20;

    //不带参数的构造方法
    public Student(){
        System.out.println("Student()");
    }

    private Student(String name,int age) {
        this.name = name;
        this.age = age;
        System.out.println("Student(String,name)");
    }

    private void eat(){
        System.out.println("i am eat");
    }

    public void sleep(){
        System.out.println("i am pig");
    }

    private void function(String str) {
        System.out.println(str);
    }

    @Override
    public String toString() {
        return "Student{" + "name='" + name + '\'' + ", age=" + age + '}';
    }
}

public class Demo01 {

    public static void main(String[] args) throws ClassNotFoundException {
        //1.通过Class对象的forName（）静态方法获取（用的最多，注意抛异常）
        Class<?> c1 = Class.forName("reflectdemo.Student");
        //2.通过getClass获取class对象
        Student student = new Student();
        Class<?> c2 = student.getClass();
        //3.直接通过 类型.class获取（更安全可靠，程序性能更高）
        Class<?> c3 = Student.class;
    }
}
